package demo06;

import com.sun.org.apache.xpath.internal.operations.String;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;

/**
 * 第六题:	通过代码, 完成如下需求:
 * 1. 定义ArrayList集合, 存储5个学生对象(姓名, 语文成绩, 数学成绩).
 * 2. 按照总成绩降序排列.
 */
public class demo06 {
    public static void main(String[] args) {
        //定义ArrayList集合, 存储5个学生对象(姓名, 语文成绩, 数学成绩).
        ArrayList<Student> arr = new ArrayList<Student>();
        arr.add(new Student("jack", 15, 52));
        arr.add(new Student("tom", 45, 72));
        arr.add(new Student("jerry", 15, 82));
        arr.add(new Student("saber", 95, 92));
        arr.add(new Student("archer", 85, 52));


        Collections.sort(arr, new Comparator<Student>() {
            @Override
            public int compare(Student e1, Student e2) {
                int num1 = e2.getAllGrade() - e1.getAllGrade();
                return num1 == 0 ? 1 : num1;
            }
        });
        //按照总成绩降序排列.
        Collections.sort(arr, ((e1, e2) -> (e2.getAllGrade() - e1.getAllGrade() == 0 ?
                1 : e2.getAllGrade() - e1.getAllGrade())));
        //打印
        for (Student student : arr) {
            System.out.println(student);
        }
        Comparable<String>[] comparables = new Comparable[4];
        Arrays.sort(comparables);
        for (Comparable c : comparables) {
            System.out.println(c);
        }

    }
}
